home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / rlib.zip / RL_STR2D.PRG < prev    next >
Text File  |  1993-01-04  |  1KB  |  41 lines

  1. * Function.: STR2DATE
  2. * Author...: Richard Low
  3. * Syntax...: STR2DATE( <expC> )
  4. * Returns..: <expC> as a dBase date type variable.
  5. * Parameter: exp<c> = string type date (Jan 1, 1987)
  6. * Notes....: Converts a string in the format (January 1, 1987) to a date.
  7. *            If an invalid date string is given, an empty date is returned.
  8.  
  9. FUNCTION STR2DATE
  10. PARAMETER p_strdate
  11. PRIVATE f_mthnames, f_month, f_day, f_year
  12.  
  13. *-- take the first 3 characters of the string, and convert to numeric month
  14. f_mthnames = '  JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'
  15. f_month = INT( AT( UPPER( SUBSTR( LTRIM(p_strdate) ,1,3) ), f_mthnames ) / 3)
  16.  
  17. IF f_month = 0
  18.    *-- if not found, invalid date string
  19.    RETURN (CTOD('  /  /  '))
  20. ENDIF
  21.  
  22. *-- left pad this number with zeros and convert to string
  23. f_month = SUBSTR(STR(f_month+100,3,0),2,2)
  24.  
  25. *-- the day starts at the first space, VAL will stop at a space or comma
  26. f_day = INT( VAL( SUBSTR( p_strdate, AT(' ',p_strdate) ) ) )
  27.  
  28. *-- convert this numeric day to zero padded string
  29. f_day = SUBSTR(STR(f_day+100,3,0),2,2)
  30.  
  31. f_year = VAL( SUBSTR( p_strdate, AT(',',p_strdate)+1 ) )
  32.  
  33. *-- see if they gave full year or short year (full year > 100)
  34. f_year = IF( f_year > 100, STR(f_year,4,0), '00' + STR(f_year,2,0) )
  35.  
  36. *-- now get just the last 2 digits
  37. f_year = SUBSTR(f_year,3,2)
  38.  
  39. *-- now concoct date by adding string month, string day, and str year
  40. RETURN ( CTOD( f_month + '/' + f_day + '/' + f_year ) )
  41.